package com.tianzhu.web;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.tianzhu.domain.User;
import com.tianzhu.repositories.UserRepo;
import com.tianzhu.service.UserService;

@Controller
@Slf4j
public class HomeController {
	
	@Autowired
	UserService up;
	
	
	@RequestMapping({"/","/home"})
    public String home(Model model){
		/*User u=up.findByUsername("root");
		String h=u.getUsername()+":"+u.getPassword()+":"+u.getUserAuthorities().get(0).getAuthority()+":"+u.getEnabled();
		model.addAttribute("h", h);
		return "pages/home";*/
		log.info("home");
		return "pages/home";
	}
	
	@PreAuthorize("hasRole('ROLE_ROOT')")
	 @RequestMapping("/greeting")
	    public String greeting(HttpServletRequest request,@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
	        String hi = request.getServletContext().getRealPath("/");
	        System.out.println();
	        model.addAttribute("name", hi);
	       
	        return "greeting";
	    }
	
	@RequestMapping("/about")
    public String about(){
        return "pages/about";
    }
	
}
